#include<iostream>
using namespace std;
const int N = 55;
int n;
int a[N];
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		int idx = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (a[i] < a[i - 1]) {
				idx = i;
			}
		}
		if (!idx)cout << 0 << endl;
		else {
			int ans = 0;
			for (int i = 1; i < idx; i++) {
				ans = max(ans, a[i]);
			}
			cout << ans << endl;
		}
	}
	return 0;
}